/*
 * Copyright (c) 2010 Philip Foulkes <philip.foulkes@gmail.com>
 *
 * This file is free software and is made available under the 
 * terms of the GNU General Public License, version 2, or at your
 * option, any later version
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#ifndef _MRP_PRIVATE_H_
#define _MRP_PRIVATE_H_

#define MRP_PRINT_INFO(fmt,args...) printk (KERN_INFO "MRP: " fmt, ## args)

#ifdef MRP_DEBUG
	#define MRP_PRINT_DEBUG(fmt,args...) printk (KERN_DEBUG "MRP Debug: " fmt, ## args)
#else
	#define MRP_PRINT_DEBUG(fmt,args...)
#endif

#define MRP_GET_CONTEXT_ALLOC_FLAG in_atomic () ? GFP_ATOMIC : GFP_KERNEL

#include "mrp.h"

struct mrp_mrpdu;
struct mrp;
struct mrp_leave_all;
struct mrp_periodic_transmission;
struct mrp_state_machine;
struct mrp_attribute;
struct mrp_applicant;

int mrp_add_indication_functions(struct mrp * mrp, mrp_mad_join_indication mrp_mad_join_indication, mrp_mad_leave_indication mrp_mad_leave_indication);

struct mrp_map * mrp_get_mrp_map(struct mrp * mrp);

int mrp_start_jointimer (struct mrp * mrp);

/**
*   These methodes are used to notify the MRP application of various events. These methods return quickly and the actual work is handed over to a central worker thread.
*   These methods are thread safe, and can be called from any context. 
*/
int mrp_receive_mrpdu_notify (struct mrp * mrp, struct mrp_mrpdu * mrp_mrpdu);

int mrp_leave_all_timer_expire_notify (struct mrp * mrp, struct mrp_leave_all * mrp_leave_all);
int mrp_periodic_timer_expire_notify (struct mrp * mrp, struct mrp_periodic_transmission * mrp_periodic_transmission);
int mrp_registrar_leave_timer_expire_notify (struct mrp * mrp, struct mrp_attribute * mrp_attribute);
/* ==================================================================================================================== */

/**
*   These methods are used to perform the work related to the various events. These methods should only be called from the message processing thread
*/
int mrp_perform_periodic_protocol_action (struct mrp * mrp);
int mrp_perform_receive_leave_all (struct mrp * mrp, int also_notify_leave_all);

int mrp_perform_jointimer_expire (struct mrp * mrp);
int mrp_perform_request_transmit_opportunity (struct mrp * mrp, struct mrp_state_machine * mrp_state_machine);

int mrp_perform_receive_mrpdu (struct mrp * mrp, struct mrp_mrpdu * mrp_mrpdu);

int mrp_perform_mad_join_request  (struct mrp * mrp, int mrp_attribute_type, void * attribute_value, int four_packed_type, int new);
int mrp_perform_mad_leave_request (struct mrp * mrp, int mrp_attribute_type, void * attribute_value, int four_packed_type);
int mrp_perform_mad_join_indication  (struct mrp * mrp, int mrp_attribute_type, void * attribute_value, int four_packed_type, int new);
int mrp_perform_mad_leave_indication (struct mrp * mrp, int mrp_attribute_type, void * attribute_value, int four_packed_type);

int mrp_perform_send_join  		(struct mrp * mrp, struct mrp_attribute * mrp_attribute);
int mrp_perform_send_new   		(struct mrp * mrp, struct mrp_attribute * mrp_attribute);
int mrp_perform_send_leave 		(struct mrp * mrp, struct mrp_attribute * mrp_attribute);
int mrp_perform_send	   		(struct mrp * mrp, struct mrp_attribute * mrp_attribute);
int mrp_perform_send_leave_all 	(struct mrp * mrp);

int mrp_perform_leave_request_on_all_attributes (struct mrp * mrp);
/* ==================================================================================================================== */

#endif
